package com.c.listener;

import java.util.Map;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.c.model.User;
import com.c.service.admin.in.IAdmin;
import com.c.util.SpringUtils;

public class SystemInitListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
		System.out.println("初始化方法开始执行...");
		// arg0.getServletContext().setAttribute("user", "admin");
		Map<String, IAdmin> govUploadIfaceClassList = SpringUtils.getApplicationContext().getBeansOfType(IAdmin.class);
		for (IAdmin govClass : govUploadIfaceClassList.values()) {
			User user = new User();
			user.setUsername("admin");
			user.setPassword("admin");
			System.out.println(govClass.islogin(user));
		}
	}

}
